package com.lc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lc.mapper.UmsUserMapper;
import com.lc.pojo.UmsUser;
import com.lc.service.UmsUserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class UmsUserServiceImpl extends ServiceImpl<UmsUserMapper,UmsUser> implements UmsUserService {

    @Transactional
    @Override
    public UmsUser getUserToken(String phone) {
        LambdaQueryWrapper<UmsUser> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UmsUser::getAccount,phone);
        UmsUser umsUser = baseMapper.selectOne(wrapper);

        //为该用户自动注册
        if(umsUser == null){
            umsUser = new UmsUser();
            umsUser.setAccount(phone);
            umsUser.setUserName(phone);
            baseMapper.insert(umsUser);
        }
        return umsUser;
    }

}
